package com.dfbz.demo01_Reader;

import java.io.FileReader;
import java.io.Reader;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo03_读取一个字符数组 {

    public static void main(String[] args) throws Exception{

        Reader reader = new FileReader("001.txt");

        char[] data = new char[2];
        int len;

        while ((len = reader.read(data))!=-1){
            // 代表读取到了有效字符
            System.out.println(new String(data,0,len));
        }

        reader.close();
    }

    public static void test(String[] args) throws Exception {
        Reader reader = new FileReader("001.txt");


        char[] data = new char[2];
        int len = reader.read(data);
        System.out.println(new String(data, 0, len == -1 ? 0 : len) + "-----------读取到的有效字符个数: " + len);

        len = reader.read(data);
        System.out.println(new String(data, 0, len == -1 ? 0 : len) + "-----------读取到的有效字符个数: " + len);

        len = reader.read(data);
        System.out.println(new String(data, 0, len == -1 ? 0 : len) + "-----------读取到的有效字符个数: " + len);

        len = reader.read(data);
        System.out.println(new String(data, 0, len == -1 ? 0 : len) + "-----------读取到的有效字符个数: " + len);


        reader.close();
    }
}
